// Page8.js
Page({
  data: {
    status:null,
    account: '',
    allInputs: {
      inputValue1: '',
      inputValue2: '',
      inputValue3: '',
      inputValue4: '',
      inputValue5: '',
      inputValue6: ''
    }
  },
  
  onLoad: function(options) {
    // 从 App 对象获取所有输入值
    this.setData({
      account: options.account,
      status:options.status
    });
    const app = getApp();
    const allInputs = app.globalData.allInputs;
    console.log("page8:");
    this.setData({ allInputs });
  },

  submitAll: function() {
    console.log("submitAll");
    var type;
    if(this.data.status=='0'){
      type='add_aplly'
    }
    else{
      type='modify'
    }
    wx.cloud.callFunction({
      name: "Check_manage",
      config: {
        env: this.data.envId
      },
      data: {
        type: type,
        data: {
          account: this.data.account,
          family_background: this.data.allInputs.inputValue1,
          political_thought: this.data.allInputs.inputValue2,
          learning_condition: this.data.allInputs.inputValue3,
          social_practice: this.data.allInputs.inputValue4,
          innovation_ability: this.data.allInputs.inputValue5,
          mixed_ability: this.data.allInputs.inputValue6
        }
      },
      success: res => {
        console.log(res.result.message);
        wx.showToast({
          title: res.result.message,
          icon: "none"
        });

        // 更新全局变量 isApplicationSubmitted 为 true
        const app = getApp();
        app.globalData.isApplicationSubmitted = true;
        console.log(this.data);
        // 跳转到 page2 页面
        wx.reLaunch({
          url: '/pages/page2/page2?account=' + this.data.account
        });
      },
      fail: res => {
        wx.showToast({
          title: '上传失败',
          icon: "none"
        });
      }
    });
    console.log("结束");
  }
});
